/*     */ package com.qmsk.business.member.memberGift.controller;
/*     */ 
/*     */ import com.qmsk.business.member.memberGift.dao.MemberGiftDAO;
/*     */ import com.qmsk.business.shopList.ShopMap;
/*     */ import com.utils.basic.ObjectComm;
/*     */ import com.utils.file.DownloadFile;
/*     */ import com.utils.file.GlobalParams;
/*     */ import com.utils.file.UploadFile;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.sql.SQLException;
/*     */ import java.util.List;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.commons.lang.StringUtils;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/memberGift"})
/*     */ public class MemberGiftController
/*     */ {
/*  36 */   private static final Logger logger = Logger.getLogger(MemberGiftController.class);
/*     */ 
/*     */   @Autowired
/*     */   private MemberGiftDAO dao;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListAll(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  62 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  64 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopId(shopId, nPageIdx, 
/*  65 */         nPageSize);
/*  66 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/*  68 */       logger.error(e);
/*  69 */       ResponseUtils.setErrorMsgResponse(
/*  70 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/smallType/{shopId}/{stId}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListPageOfSmallTypeId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId, @PathVariable("stId") Integer smallTypeId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  90 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  92 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopId_stId(shopId, smallTypeId, 
/*  93 */         nPageIdx, nPageSize);
/*  94 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/*  96 */       logger.error(e);
/*  97 */       ResponseUtils.setErrorMsgResponse(
/*  98 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/largeType/{shopId}/{ltId}/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListPageOfLargeTypeId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Integer shopId, @PathVariable("ltId") Integer largeTypeId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/* 118 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/* 120 */       GsonEbRst gsonEbRst = this.dao.getGsonOfShopId_ltId(shopId, largeTypeId, 
/* 121 */         nPageIdx, nPageSize);
/* 122 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (SQLException e) {
/* 124 */       logger.error(e);
/* 125 */       ResponseUtils.setErrorMsgResponse(
/* 126 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 142 */     String sGsonInData = request.getParameter("data");
/*     */     try
/*     */     {
/* 145 */       int nResult = this.dao.insertJsonOneRow(sGsonInData);
/* 146 */       if (nResult > 0) {
/* 147 */         Long id = this.dao.getLastId();
/* 148 */         DbConnection.commit();
/* 149 */         ResponseUtils.setResponseResult(id, response);
/* 150 */         return; }
/* 151 */       DbConnection.rollback();
/* 152 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 153 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 154 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 157 */       DbConnection.rollback();
/* 158 */       logger.error(e);
/* 159 */       ResponseUtils.setErrorMsgResponse(
/* 160 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 161 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   private String mergeApacheSubUrl(String sRoot, Long shopId, Long giftId, String sSub)
/*     */   {
/* 167 */     return sRoot + String.valueOf(ShopMap.getGroupIdOfShopIdDef(shopId)) + 
/* 168 */       "/" + "shop/" + String.valueOf(shopId) + "/" + 
/* 169 */       "gift/" + giftId + "/" + sSub;
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert2(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/* 176 */     String sGsonInData = request.getParameter("data");
/*     */     try {
/* 178 */       int nResult = 0;
/* 179 */       ParserDataSetJson p = ParserDataSetJson.fromString(sGsonInData);
/* 180 */       if (p == null) {
/* 181 */         ResponseUtils.setErrorMsgResponse("请求错误", response);
/* 182 */         return;
/*     */       }
/* 184 */       Long id = null;
/* 185 */       nResult = this.dao.applyUpdatesNo(p, "id");
/* 186 */       if ((nResult > 0) && (p.isExistsInsertRows())) {
/* 187 */         for (GsonHeadOneRow g : p.getListInsertRows()) {
/* 188 */           id = ObjectComm.objectToLong(g.getValueOfName("id"));
/* 189 */           String path = mergeApacheSubUrl(
/* 190 */             GlobalParams.getGlobalParams().getApacheUrl(), shopId, id, 
/* 191 */             "img/");
/* 192 */           for (int i = 0; i < 5; ++i) {
/* 193 */             String fldName = null;
/* 194 */             switch (i)
/*     */             {
/*     */             case 0:
/* 196 */               fldName = "ImageURL";
/* 197 */               break;
/*     */             case 1:
/* 199 */               fldName = "ImageURL1";
/* 200 */               break;
/*     */             case 2:
/* 202 */               fldName = "ImageURL2";
/* 203 */               break;
/*     */             case 3:
/* 205 */               fldName = "ImageURL3";
/* 206 */               break;
/*     */             case 4:
/* 208 */               fldName = "ImageURL4";
/*     */             }
/*     */ 
/* 211 */             if (StringUtils.isNotEmpty(fldName)) {
/* 212 */               String url = (String)g.getValueOfName(fldName);
/* 213 */               if (StringUtils.isNotEmpty(url)) {
/* 214 */                 String ss = url
/* 215 */                   .substring(url.lastIndexOf("\\") + 1);
/* 216 */                 this.dao.updateImgUrl(fldName, path + ss, id);
/*     */               }
/*     */             }
/*     */           }
/*     */         }
/*     */       }
/* 222 */       if (nResult > 0)
/* 223 */         DbConnection.commit();
/*     */       else {
/* 225 */         DbConnection.rollback();
/*     */       }
/* 227 */       if (nResult > 0) {
/* 228 */         String[] heads = { "id" };
/* 229 */         Object[] datas = { id };
/* 230 */         ResponseUtils.toGsonEbRst(heads, datas, response);
/* 231 */         return; }
/* 232 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 233 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 234 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 237 */       DbConnection.rollback();
/* 238 */       logger.error(e);
/* 239 */       ResponseUtils.setErrorMsgResponse(
/* 240 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 241 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response) {
/* 248 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 250 */       String[] strParams = id.split(",");
/* 251 */       int nResult = this.dao.deleteParams(strParams);
/* 252 */       DbConnection.commit();
/* 253 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 254 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 255 */         response);
/*     */     } catch (Exception e) {
/* 257 */       DbConnection.rollback();
/* 258 */       logger.error(e);
/* 259 */       ResponseUtils.setErrorMsgResponse(
/* 260 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 261 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/* 270 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 272 */       String[] strParams = id.split(",");
/* 273 */       int nResult = this.dao.deleteParams(strParams);
/* 274 */       DbConnection.commit();
/* 275 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 276 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 277 */         response);
/*     */     } catch (Exception e) {
/* 279 */       DbConnection.rollback();
/* 280 */       logger.error(e);
/* 281 */       ResponseUtils.setErrorMsgResponse(
/* 282 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 283 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void update(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 300 */     String id = request.getParameter("id");
/* 301 */     String sGsonInData = request.getParameter("data");
/*     */     try {
/* 303 */       GsonHeadOneRow g = GsonHeadOneRow.jsonStrToObject(sGsonInData);
/* 304 */       if (g == null) {
/* 305 */         ResponseUtils.setErrorMsgResponse(
/* 306 */           RequestUtils.getReadJsonDataErrorMessage(request), 
/* 307 */           response);
/*     */       } else {
/* 309 */         int nResult = this.dao.updateJsonOneRow(g, id);
/* 310 */         ResponseUtils.setSqlResultResponse(nResult, 
/* 311 */           RequestUtils.getSqlUpdateErrorMessage(sGsonInData, request), 
/* 312 */           response);
/*     */       }
/* 314 */       DbConnection.commit();
/*     */     } catch (Exception e) {
/* 316 */       DbConnection.rollback();
/* 317 */       logger.error(e);
/* 318 */       ResponseUtils.setErrorMsgResponse(
/* 319 */         RequestUtils.getSqlUpdateErrorMessage(sGsonInData, request) + 
/* 320 */         ":" + e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void update2(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/* 328 */     String sData = RequestUtils.getStringOfData(request);
/*     */     try {
/* 330 */       int nResult = 0;
/* 331 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 332 */       if ((p != null) && (p.isExistsUpdateRows())) {
/* 333 */         for (int n = 0; n < p.getListUpdateRows().size(); ++n) {
/* 334 */           GsonHeadOneRow g = (GsonHeadOneRow)p.getListUpdateRows().get(n);
/* 335 */           Long id = ObjectComm.objectToLong(g.getValueOfName("id"));
/* 336 */           String path = mergeApacheSubUrl(
/* 337 */             GlobalParams.getGlobalParams().getApacheUrl(), shopId, id, 
/* 338 */             "img/");
/* 339 */           for (int i = 0; i < 5; ++i) {
/* 340 */             String fldName = null;
/* 341 */             switch (i)
/*     */             {
/*     */             case 0:
/* 343 */               fldName = "ImageURL";
/* 344 */               break;
/*     */             case 1:
/* 346 */               fldName = "ImageURL1";
/* 347 */               break;
/*     */             case 2:
/* 349 */               fldName = "ImageURL2";
/* 350 */               break;
/*     */             case 3:
/* 352 */               fldName = "ImageURL3";
/* 353 */               break;
/*     */             case 4:
/* 355 */               fldName = "ImageURL4";
/*     */             }
/*     */ 
/* 358 */             if (StringUtils.isNotEmpty(fldName)) {
/* 359 */               String url = (String)((GsonHeadOneRow)p.getListUpdateRows().get(n))
/* 360 */                 .getValueOfName(fldName);
/* 361 */               if (StringUtils.isNotEmpty(url)) {
/* 362 */                 String ss = url
/* 363 */                   .substring(url.lastIndexOf("\\") + 1);
/* 364 */                 ((GsonHeadOneRow)p.getListUpdateRows().get(n))
/* 365 */                   .autoAddHeadData(fldName, path + ss);
/*     */               }
/*     */             }
/*     */           }
/*     */         }
/* 370 */         nResult = this.dao.applyUpdates(p);
/* 371 */         if (nResult > 0)
/* 372 */           DbConnection.commit();
/*     */         else {
/* 374 */           DbConnection.rollback();
/*     */         }
/*     */       }
/* 377 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 378 */         RequestUtils.getSqlUpdateErrorMessage(sData, request), 
/* 379 */         response);
/*     */     } catch (Exception e) {
/* 381 */       DbConnection.rollback();
/* 382 */       logger.error(e);
/* 383 */       ResponseUtils.setErrorMsgResponse(
/* 384 */         RequestUtils.getSqlUpdateErrorMessage(sData, request) + ":" + 
/* 385 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"upload/giftImg/{shopId}/{giftId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void uploadGiftImg(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("giftId") Long giftId)
/*     */   {
/*     */     try
/*     */     {
/* 403 */       String path = mergeApacheSubUrl(GlobalParams.getGlobalParams()
/* 404 */         .getApacheRoot(), shopId, giftId, "img/");
/* 405 */       UploadFile.uploadFileOfRequest(request, response, path);
/* 406 */       ResponseUtils.setSuccessResponse("上传图片成功", response);
/*     */     } catch (Exception e) {
/* 408 */       logger.error(e);
/* 409 */       ResponseUtils.setErrorMsgResponse("上传礼品图片出错:" + e.getMessage(), 
/* 410 */         response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"download/giftImg/{shopId}/{giftId}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void downloadGiftImg(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") String shopId, @PathVariable("giftId") String giftId)
/*     */   {
/* 419 */     String fileName = RequestUtils.getString(request, "fileName");
/*     */     try {
/* 421 */       DownloadFile.download(response, GlobalParams.getGlobalParams()
/* 422 */         .getDataPath() + shopId + "/" + giftId + "/" + fileName);
/*     */     } catch (Exception e) {
/* 424 */       logger.error(e);
/* 425 */       ResponseUtils.setErrorMsgResponse("下传礼品图片出错:" + e.getMessage(), 
/* 426 */         response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"nav/giftImg/{shopId}/{giftId}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void navigateGiftImg(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") String shopId, @PathVariable("giftId") String giftId)
/*     */   {
/* 435 */     String fileName = RequestUtils.getString(request, "fileName");
/*     */     try {
/* 437 */       boolean bool = DownloadFile.navigate(response, 
/* 438 */         GlobalParams.getGlobalParams().getDataPath() + 
/* 439 */         shopId + 
/* 440 */         "/" + 
/* 441 */         giftId + 
/* 442 */         "/" + fileName);
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 450 */       logger.error(e);
/* 451 */       ResponseUtils.setErrorMsgResponse("浏览礼品图片出错:" + e.getMessage(), 
/* 452 */         response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.member.memberGift.controller.MemberGiftController
 * JD-Core Version:    0.5.3
 */